package teamproject.graphEditor;

import java.util.ArrayList;

public class Node {

	private String name = "";
	private int id = -1;
	private boolean visited = false;
	private ArrayList<Integer> edgeID = new ArrayList<Integer>();
	private ArrayList<ArrayList<Float>> buffer = new ArrayList<ArrayList<Float>>();
	private float x = -0.0f;
	private float y = -0.0f;

	/**
	 * Instantiates a new node.
	 * 
	 * @param name
	 *            the name
	 */
	public Node(String name) {
		this.name = name;
	}

	/**
	 * Instantiates a new node.
	 * 
	 * @param name
	 *            the name
	 * @param ID
	 *            the iD
	 */
	public Node(String name, int ID) {
		this.name = name;
		this.id = ID;
	}

	private void addBuffer(ArrayList<Float> buffer, int edgeId) {
		// works
		getBuffer().add(buffer);
		this.getEdgeID().add(edgeId);
	}

	public void addToBuffer(float bufferValue, int edgeId) {
		int i = findIndex(edgeId);
		if (i != -1) {
			getBuffer().get(i).add(bufferValue);
		} else {
			ArrayList<Float> newArray = new ArrayList<Float>();
			newArray.add(bufferValue);
			this.addBuffer(newArray, edgeId);
		}
	}

	private synchronized int findIndex(int edgeId) {
		for (int i = 0; i < this.getEdgeID().size(); i++) {

			if (getEdgeID().get(i).intValue() == edgeId) {
				return i;
			}
		}
		return -1;
	}

	private ArrayList<ArrayList<Float>> getBuffer() {
		return buffer;
	}

	public float getDataValue(int edgeId, int index) {
		int i = findIndex(edgeId);
		return this.getBuffer().get(i).get(index);
	}

	public ArrayList<Integer> getEdgeID() {
		return edgeID;
	}

	public int getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public boolean hasBeenVisited() {
		return visited;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setVisited(boolean visited) {
		this.visited = visited;
	}

	public void setX(float x) {
		this.x = x;
	}

	public void setY(float y) {
		this.y = y;
	}

	@Override
	public String toString() {
		return name;
	}
}
